package com.day0916.task;

import java.util.Scanner;

public class Method_management {
    Scanner in = new Scanner(System.in);

    DishManager dishManager = new DishManager();
    OrdersManager ordersManager = new OrdersManager();

    //初始化数据
    public void initDish(){
        dishManager.initDish();
        ordersManager.initOrders();
        ordersManager.dishManager = dishManager;
    }

    //   打印菜单
    public void printMenu(){
        System.out.println("欢迎使用“吃货联盟订餐系统”");
        System.out.println("*****************************************");
        System.out.println("1.我要订餐");
        System.out.println("2.查看餐袋");
        System.out.println("3.签收订单");
        System.out.println("4.修改订单");
        System.out.println("5.删除订单");
        System.out.println("6.我要点赞");
        System.out.println("7.添加菜品");
        System.out.println("8.修改菜品价格");
        System.out.println("9.删除菜品");
        System.out.println("10.退出系统");
        System.out.println("*****************************************");
    }

    //   选择菜单
    public int chooseMenu(){
        System.out.print("请输入数字1-9选择，输入0返回：");
        int choose = in.nextInt();
        switch (choose){
            case 1:
                System.out.println("***1.我要订餐***");
                orderDish();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 2:
                System.out.println("***2.查看餐袋***");
                viewMealBag();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 3:
                System.out.println("***3.签收订单***");
                signInOrder();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 4:
                System.out.println("***4.修改订单***");
                change_order();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 5:
                System.out.println("***5.修改订单***");
                deleteOrder();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 6:
                System.out.println("***6.我要点赞***");
                giveTheThumbsUp();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 7:
                System.out.println("***7.添加菜品***");
                add();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 8:
                System.out.println("***8.修改菜品价格***");
                revise();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 9:
                System.out.println("***9.删除菜品***");
                del();
                System.out.print("输入0返回：");
                choose = in.nextInt();
                break;
            case 10:
                System.out.println("谢谢使用，欢迎下次光临！");
                System.exit(0);//退出系统
                break;
            case 0:
                break;
            default:
                System.out.println("请输入0-9的数字：");
                choose = in.nextInt();
                break;
        }
        return choose;
    }

    //    1   我要订餐
    public void orderDish(){
        dishManager.showDish();

        System.out.print("请输入订餐人姓名：");
        String user_name = in.next();//订餐姓名
        System.out.print("请选择您需要的菜品编号：");
        int dish_no = in.nextInt();//菜品编号
        System.out.print("请输入您需要的份数：");
        int dish_quantity = in.nextInt();//菜品数量
        System.out.print("请输入送餐时间（送餐时间是10点到20点整点送餐）：");
        int time = in.nextInt();//送餐时间
        if(time < 10 || time > 20){
            System.out.println("您的输入有误，请重新输入（送餐时间是10点到20点整点送餐）：");
            time = in.nextInt();
        }
        System.out.println("请输入送餐地址：");
        String address = in.next();//送餐地址
        //计算订单总价
        double sum = dishManager.dishes[dish_no - 1].dishPrice * dish_quantity;//菜品总金额
        double meal_delivery_fee = sum >= 50 ? 0 : 5;//送餐费
        double sums = sum + meal_delivery_fee;//加送餐费的总金额
        System.out.println("订餐成功！");
        System.out.println("您订的是：" + dishManager.dishes[dish_no - 1].dishName + " " + dish_quantity + "份");
        System.out.println("送餐时间：" + time + "点");
        System.out.println("餐费：" + sum + "元,送餐费：" + meal_delivery_fee + "元，总计：" + sums + "元。");
        //添加订单方法
        ordersManager.addOrder(user_name,time,address,sum,dish_no,dish_quantity);

    }

    //    2  查看餐袋
    public void viewMealBag(){
        System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t\t\t总金额\t订单状态");
        ordersManager.viewMealBags();
    }

    //    3  签收订单
    public void signInOrder(){
        viewMealBag();
        System.out.print("请选择要签收的订单序号：");
        int order_no = in.nextInt();
        ordersManager.signInOrders(order_no);
    }

    //    4  修改订单
    public void change_order(){
        viewMealBag();
        System.out.print("请输入要修改的订单编号：");
        int orderN0 = in.nextInt();
        ordersManager.change_orders(orderN0);
    }

    //   5   删除订单
    public void deleteOrder(){
        viewMealBag();
        System.out.print("请输入要删除的订单序号：");
        int del_order = in.nextInt();
        ordersManager.deleteOrders(del_order);
    }


    //   6   我要点赞
    public void giveTheThumbsUp(){
        dishManager.showDish();
        System.out.print("请输入您要点赞的菜品序号：");
        int fab_num = in.nextInt();//菜品序号
        if(fab_num > dishManager.dishes.length ||fab_num < 0){
            System.out.print("输入错误，请重新输入您要点赞的菜品序号（1-" + dishManager.dishes.length + ")：");
            fab_num = in.nextInt();
        }
        dishManager.giveTheThumbsUps(fab_num);
        System.out.println("点赞成功！");
    }

    //   7   添加菜品
    public void add(){
        System.out.print("请输入添加菜品的名字：");
        String dishName = in.next();
        System.out.print("请输入添加菜品的价格：");
        double dishPrice = in.nextDouble();
        dishManager.addDish(dishName,dishPrice);
        System.out.println("添加成功！");
    }

    //  8  修改价格
    public void revise(){
        dishManager.showDish();
        System.out.print("请输入要修改价格的菜品编号：");
        int no = in.nextInt();
        System.out.print("请输入新的菜品价格：");
        double price = in.nextDouble();
        dishManager.revisePrice(no,price);
    }

    //   9  删除菜品
    public void del(){
        dishManager.showDish();
        System.out.print("请输入要删除的菜品序号：");
        int no = in.nextInt();
        dishManager.delDish(no);
        System.out.println("删除成功！");
    }
}
